package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CaseFamilyMembers;
import com.ruoyi.system.service.ICaseFamilyMembersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病例家庭成员Controller
 * 
 * @author ruoyi
 * @date 2022-04-03
 */
@Controller
@RequestMapping("/system/CaseFamilyMembers")
public class CaseFamilyMembersController extends BaseController
{
    private String prefix = "system/CaseFamilyMembers";

    @Autowired
    private ICaseFamilyMembersService caseFamilyMembersService;

    @RequiresPermissions("system:CaseFamilyMembers:view")
    @GetMapping()
    public String CaseFamilyMembers()
    {
        return prefix + "/CaseFamilyMembers";
    }

    /**
     * 查询病例家庭成员列表
     */
    @RequiresPermissions("system:CaseFamilyMembers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CaseFamilyMembers caseFamilyMembers)
    {
        startPage();
        List<CaseFamilyMembers> list = caseFamilyMembersService.selectCaseFamilyMembersList(caseFamilyMembers);
        return getDataTable(list);
    }

    /**
     * 导出病例家庭成员列表
     */
    @RequiresPermissions("system:CaseFamilyMembers:export")
    @Log(title = "病例家庭成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CaseFamilyMembers caseFamilyMembers)
    {
        List<CaseFamilyMembers> list = caseFamilyMembersService.selectCaseFamilyMembersList(caseFamilyMembers);
        ExcelUtil<CaseFamilyMembers> util = new ExcelUtil<CaseFamilyMembers>(CaseFamilyMembers.class);
        return util.exportExcel(list, "病例家庭成员数据");
    }

    /**
     * 新增病例家庭成员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存病例家庭成员
     */
    @RequiresPermissions("system:CaseFamilyMembers:add")
    @Log(title = "病例家庭成员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CaseFamilyMembers caseFamilyMembers)
    {
        return toAjax(caseFamilyMembersService.insertCaseFamilyMembers(caseFamilyMembers));
    }

    /**
     * 修改病例家庭成员
     */
    @RequiresPermissions("system:CaseFamilyMembers:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CaseFamilyMembers caseFamilyMembers = caseFamilyMembersService.selectCaseFamilyMembersById(id);
        mmap.put("caseFamilyMembers", caseFamilyMembers);
        return prefix + "/edit";
    }

    /**
     * 修改保存病例家庭成员
     */
    @RequiresPermissions("system:CaseFamilyMembers:edit")
    @Log(title = "病例家庭成员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CaseFamilyMembers caseFamilyMembers)
    {
        return toAjax(caseFamilyMembersService.updateCaseFamilyMembers(caseFamilyMembers));
    }

    /**
     * 删除病例家庭成员
     */
    @RequiresPermissions("system:CaseFamilyMembers:remove")
    @Log(title = "病例家庭成员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(caseFamilyMembersService.deleteCaseFamilyMembersByIds(ids));
    }
}
